package de.softwareforge.published;

/*
 * Copyright (C) 2007-2008 Henning P. Schmiedehausen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.util.ArrayList;
import java.util.List;


/**
 * Test program for the Published doclet/taglet.
 *
 * @author <a href="mailto:henning@schmiedehausen.org">Henning P. Schmiedehausen</a>
 * @version $Id: JavaDoc.java 103 2008-02-24 22:24:35Z hps@intermeta.de $
 * @api.level unpublished
 */
public class JavaDoc
{

    /**
     * Run demo program.
     *
     * @param args The command line arguments.
     */
    public static void main(String[] args)
    {
        String[] params =
            new String[]
            {
                "-use",
                "-encoding",
                "UTF-8",
                "-docencoding",
                "UTF-8",
                "-version",
                "-author",
                "-link",
                "http://java.sun.com/javase/6/docs/api/",
                "-link",
                "http://java.sun.com/javase/6/docs/jdk/api/javadoc/doclet/",
                "-sourcepath",
                "src/java",
                "de.softwareforge.published",
                "de.softwareforge.published.taglet",
                "de.softwareforge.published.doclet",
                "de.softwareforge.published.util",
                "de.softwareforge.published.proxy",
            };

        String[] doclet =
            new String[]
            {

                "-taglet",
                "de.softwareforge.published.taglet.PublishedTaglet",
                "-doclet",
                "de.softwareforge.published.doclet.PublishedDoclet",
                "-docletpath",
                "classes",
                "-tagletpath",
                "classes",
            };

        renderApidocs("apidoc/ignore", new String[][] { doclet, params, new String[] { 
                        "-notimestamp", "-version", "-author", "-use", 
                        "-windowtitle" , "${name} ${version} API",
                        "-doctitle" , "${name} ${version} API",
                        "-defaultpublishlevel" , "unpublished", 
                        "-publishlevel" , "published unstable",
                        "-hideuntagged", 
                        "-novisibilitychanges", 
                    } });
    }

    /**
     * Render API docs using the given settings.
     *
     * @param targetDir Directory to render into.
     * @param params Parameter sets used for rendering.
     */
    public static void renderApidocs(final String targetDir, final String[][] params)
    {
        File target = new File(targetDir);
        target.mkdirs();

        final List<String> javadocParams = new ArrayList<String>(20);
        javadocParams.add("-d");
        javadocParams.add(targetDir);

        for (int i = 0; i < params.length; i++)
        {
            for (int j = 0; j < params[i].length; j++)
            {
                javadocParams.add(params[i][j]);
            }
        }

        String[] opts = javadocParams.toArray(new String[javadocParams.size()]);
        int result = com.sun.tools.javadoc.Main.execute(opts);
        System.out.println("Javadoc returned: " + result);
    }
}
